%%
%%  Copyright 2016-2023 Obster-Y
%%
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2005/12/01 or later.
%%
%%  This work has the LPPL maintenance status `maintained'.
%%
%%  The Current Maintainer of this work is Obster-Y.
%%
%%  This work contains source codes from `beamerouterthemesjtubeamer.dtx' devloped
%%  by sjtuG and distributed under Apache License V2.0
%%
%%  This work consists of the files beamerouterthemexjtubeamer.sty.
%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerouterthemexjtubeamer}[2023/05/28 v1.0.0 xjtubeamer outer theme]

%%%%%%%%%%%%%
%% OPTIONS %%
%%%%%%%%%%%%%

\DefineOption{outer}{nav}{miniframes}
\DefineOption{outer}{nav}{infolines}
\DefineOption{outer}{nav}{sidebar}
\DefineOption{outer}{nav}{default}
\DefineOption{outer}{nav}{smoothbars}
\DefineOption{outer}{nav}{split}
\DefineOption{outer}{nav}{shadow}
\DefineOption{outer}{nav}{tree}
\DefineOption{outer}{nav}{smoothtree}
\ExecuteOptionsBeamer{miniframes}

\DefineOption{outer}{logopos}{topright}
\DefineOption{outer}{logopos}{bottomright}
\ExecuteOptionsBeamer{bottomright}
\ProcessOptionsBeamer

\beamer@compresstrue
\if\EqualOption{outer}{logopos}{topright}
  \AtBeginDocument{
    \defbeamertemplate*{frametitle}{xjtubeamer}[1][]
    {%
      \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
      \@tempdima=\textwidth%
      \advance\@tempdima by\beamer@leftmargin%
      \advance\@tempdima by\beamer@rightmargin%
      \begin{beamercolorbox}[sep=0.15cm,leftskip=0.15cm,#1,wd=\the\@tempdima]{frametitle}
        \begingroup
        \usebeamerfont{frametitle}
        \vbox{}
        \ifx\insertframesubtitle\@empty\vskip-0.5ex%
        \else\vskip-0.7ex\fi%
        \if@tempswa\else\csname beamer@fte#1\endcsname\fi%
        \strut\insertframetitle\strut\par%
        {%
          \ifx\insertframesubtitle\@empty%
          \else%
          {
            \usebeamerfont{framesubtitle}
            \usebeamercolor[fg]{framesubtitle}
            \strut\insertframesubtitle\strut\par
          }%
          \fi
        }%
        \vskip-1.07ex%
        \endgroup%
        \raggedleft%
        \begingroup
        \ifx\insertframesubtitle\@empty\vskip-2.2ex%
        \else\vskip-3.05ex\fi%
        \resizebox{!}{3ex}{\vphantom{-}\usebeamertemplate{logo}}\hspace*{10pt}%
        \endgroup%
        \ifx\insertframesubtitle\@empty%
        \else\vskip0.75ex\fi%
        \if@tempswa\else\vskip-.3cm\fi%
      \end{beamercolorbox}%
      \vspace*{-.7cm}
    }
  }
  \if\EqualOption{outer}{nav}{default}
    \AtBeginDocument{
      \setbeamertemplate{frametitle}[xjtubeamer][leftskip=0cm,sep=0.3cm]
    }
  \fi
\fi


%%%%%%%%%%%%%%%%%%%%
%% NAVIGATION BAR %%
%%%%%%%%%%%%%%%%%%%%

\if\EqualOption{outer}{nav}{miniframes}
  \useoutertheme[footline=authortitle]{miniframes}
\else
  \if\EqualOption{outer}{nav}{sidebar}
    \useoutertheme{sidebar}
    \logo{\resizebox{!}{1cm}{\xjtubadge}}
    \def\xjtubeamer@outer@logopos{topright}
    \AtBeginDocument{
      \setbeamertemplate{frametitle}[sidebar theme]
    }
  \else
    \useoutertheme{\xjtubeamer@outer@nav}
    \setbeamercolor{title in head/foot}{use=structure,bg=white,fg=structure.fg}
  \fi
\fi

\if\EqualOption{outer}{nav}{default}
  \setbeamercolor{frametitle}{use=palette primary,
    bg=palette primary.bg,fg=palette primary.fg}
\else
  \if\EqualOption{outer}{nav}{infolines}
    \setbeamercolor{author in head/foot}{use=structure,fg=white,bg=structure}
    \setbeamercolor{title in head/foot}{use=structure,fg=structure,bg=structure!10}
    \setbeamercolor{date in head/foot}{use=structure,fg=structure,bg=structure!20}
    \setbeamercolor{section in head/foot}{parent=author in head/foot}
    \setbeamercolor{subsection in head/foot}{parent=date in head/foot}
    \setbeamersize{text margin left=1cm,text margin right=1cm}
  \else
    \setbeamercolor{frametitle}{use=titlelike,bg=white,fg=titlelike.fg}
    \setbeamercolor{frametitle right}{parent=subsection in head/foot}
  \fi
\fi

\setbeamertemplate{sidebar right}{}
\setbeamertemplate{page number in head/foot}{}

% % ADD PAGE NUMBER TO NAVIGATION BAR
% \addtobeamertemplate{navigation symbols}{}{
%   \hbox{
%     \raisebox{1.2pt}[0pt][0pt]{
%       \usebeamerfont{footline}
%       \usebeamercolor{footline}
%       \color{footline.fg!50}
%       \sffamily
%       \insertframenumber/\inserttotalframenumber
%       \hspace*{0.2em}
%     }
%   }
% }

\if\EqualOption{outer}{logopos}{bottomright}
  \addtobeamertemplate{footline}{
    \hfill%
    \usebeamertemplate***{navigation symbols}%
    \llap{\raisebox{1pc}[0pt][0pt]{\insertlogo}}
    \hspace*{0.1cm}\par
    \vskip 4pt
  }{}
\else
  \addtobeamertemplate{footline}{
    \hfill%
    \usebeamertemplate***{navigation symbols}%
    \hspace*{0.1cm}\par
    \vskip 4pt
  }{}
\fi


%%%%%%%%%%%%%%%
%% HEADLINES %%
%%%%%%%%%%%%%%%

\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
  \end{beamercolorbox}
  \begin{beamercolorbox}[
    wd=\paperwidth,%
    dp=2.5ex,%
    ht=2.5ex,%
    leftskip=.3cm,
    rightskip=.3cm plus1fil
  ]{section in head/foot}
    \usebeamerfont{section in head/foot}
    \insertnavigation{.93\paperwidth}
  \end{beamercolorbox}
  \begin{beamercolorbox}[
    wd=\paperwidth,
    dp=1.125ex,
    ht=2.5ex,%
    leftskip=.3cm,
    rightskip=.3cm plus1fil
  ]{subsection in head/foot}
    \usebeamerfont{subsection in head/foot}%
    % \insertsubsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
    \insertsubsectionhead
    \setbox\beamer@tempbox=\hbox{\insertsubsubsectionhead}%
    \ifdim\wd\beamer@tempbox>1pt%
      ：%
    % \ \raise1.9pt\hbox{\vrule width 5pt height0.4pt}\ %
      \hskip1pt%
    \fi%
    \insertsubsubsectionhead
  \end{beamercolorbox}
  \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
  \end{beamercolorbox}
}


%%%%%%%%%%%%%%%
%% FOOTLINES %%
%%%%%%%%%%%%%%%

\setbeamertemplate{footline}{%
  \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
  \end{beamercolorbox}

  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{title in head/foot}%
    \usebeamerfont{title in head/foot}
    \inserttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamercolor{navigation symbols in head/foot}%
    \raisebox{-1.5pt}[0pt][0pt]{
      \insertslidenavigationsymbol%
      \insertframenavigationsymbol%
      \insertsubsectionnavigationsymbol%
      \insertsectionnavigationsymbol%
      \insertdocnavigationsymbol%
      \insertbackfindforwardnavigationsymbol%
    }
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamercolor{navigation symbols in head/foot}%
    \insertframenumber/\inserttotalframenumber
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamercolor{author in head/foot}
    \insertauthor
    \hspace*{0.1cm}
  \end{beamercolorbox}%
  }%
  \vskip0pt%

  \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
  \end{beamercolorbox}
}

\endinput

%% EOF: beamerouterthemexjtubeamer.sty
